home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / disk / misc / SFSobject.lha / SFSobject / SFSobject.cpp next >
Encoding:
C/C++ Source or Header  |  1999-10-14  |  5.4 KB  |  153 lines

  1. /*  $Id: SFSobject.cpp 1.3 1999/10/14 17:51:30 helios Exp $
  2.  
  3.     Sets object attributes of SmartFilesystem objects
  4. */
  5.  
  6. #include <dos/dos.h>
  7. #include <dos/dosextens.h>
  8. #include <utility/tagitem.h>
  9. #include "fs/packets.h"
  10. #include "fs/query.h"
  11. #include "fs/blockstructure.h"
  12. #include "fs/nodes.h"
  13. #include "fs/objects.h"
  14.  
  15. #include <pragmas/dos_pragmas.h>
  16.  
  17. const char *version_str = "\0$VER: SFSobject 1.3 (14.10.1999) (W) by Martin Steigerwald\r\n";
  18.  
  19. #define TEMPLATE "OBJECT/A,SHOW=UNHIDE/S,HIDE/S,DELETEABLE=DELABLE/S,UNDELETEABLE=UNDELABLE/S"
  20.  
  21. main()
  22. {
  23.     struct RDArgs *rdargs=NULL;
  24.  
  25.     struct {
  26.         char  *file;
  27.         ULONG show;
  28.         ULONG hide;
  29.         ULONG delable;
  30.         ULONG undelable;
  31.     } args={NULL, 0, 0};
  32.  
  33.     rdargs = ReadArgs(TEMPLATE, (LONG *)&args, NULL);
  34.  
  35.     if (rdargs == NULL) {
  36.         PrintFault(IoErr(), "SFSobject");
  37.         return RETURN_ERROR;
  38.     }
  39.     else {
  40.         BPTR  lock=NULL;
  41.  
  42.  
  43.         // really change something?
  44.         if (args.show!=0 || args.hide!=0 || args.delable!=0 || args.undelable!=0) {
  45.  
  46.             // checking mutually exclusive options
  47.             if ((args.show!=0 && args.hide!=0) ||
  48.                 (args.delable!=0 && args.undelable!=0)) {
  49.                     Printf("Please make a clear decision. You chose mutually exclusive options.\n");
  50.             }
  51.             else {
  52.                 lock = Lock(args.file, SHARED_LOCK);
  53.                 if (lock) {
  54.                     struct DevProc *devproc=NULL;
  55.  
  56.                     devproc = GetDeviceProc(args.file, NULL);
  57.                     if (devproc) {
  58.                         struct MsgPort *port=devproc->dvp_Port;
  59.                         LONG errorcode=0;
  60.                         ULONG bits=0;
  61.                         char name[1];
  62.                         BSTR namebcpl=NULL;
  63.                         APTR rlock=NULL;
  64.  
  65.                         // quick SFS bug work around,
  66.                         // SFS 1.81 throws a hit when a pass a NULL pointer
  67.                         // to BSTR name argument in ACTION_SFS_SET_OBJECTBITS
  68.  
  69.                         name[0]=0;
  70.                         namebcpl=MKBADDR(name);
  71.  
  72.                         if (args.hide) {
  73.                             bits = bits | OTYPE_HIDDEN;
  74.                         }
  75.  
  76.                         struct TagItem tags[] = {
  77.                             ASQ_HAS_RECYCLED, 0,
  78.                             TAG_DONE
  79.                         };
  80.  
  81.                         //checking code for .recycled-directory!
  82.  
  83.                         if ((((struct FileLock *)(BADDR(lock)))->fl_Key)==2 & (args.undelable==0)) {
  84.                             Printf("I could not allow you to set the recycled directory to deleteable!\n");
  85.                             Printf("Setting UNDELETEABLE option!\n");
  86.                             args.undelable=1
  87.                         }
  88.  
  89.                         // above code saved me two dozen of lines, thanks to Jörg Strohmayer
  90.  
  91.                         // old recycled dir code that still does not work correctly
  92.                           /*
  93.                         errorcode = DoPkt(port, ACTION_SFS_QUERY, (LONG)&tags, 0, 0, 0, 0);
  94.                         if (errorcode!=DOSFALSE) {
  95.                             if (tags[0].ti_Data!=0) {
  96.                                 Printf("Has recycled!\n");
  97.                                 rlock = (APTR) DoPkt(port, ACTION_SFS_LOCATE_OBJECT, RECYCLEDNODE, SHARED_LOCK, 0, 0, 0);
  98.                                 if (rlock!=NULL) {
  99.                                     BPTR rlockbtr=(BPTR) MKBADDR(rlock);
  100.  
  101.                                     Printf("Got lock on recycled!\n");
  102.  
  103.                                     if (SameLock(lock, rlockbtr)==LOCK_SAME) {
  104.                                         Printf("Same lock\n");
  105.                                         if (args.undelable==0) {
  106.                                             Printf("I could not allow you to set .recycled to deleteable. Sorry!\n");
  107.                                         }
  108.                                         args.undelable=1
  109.                                     }
  110.  
  111.                                     UnLock(rlockbtr);
  112.                                 }
  113.                                 else {
  114.                                     Printf("This should not happen. Report to author!\n");
  115.                                     PrintFault(IoErr(), "SFSobject");
  116.                                 }
  117.                             }
  118.  
  119.                         } // has recycled?
  120.                         else {
  121.                             Printf("Could not query HAS_RECYCLED. No SFS volume?\n");
  122.                             PrintFault(IoErr(), "SFSobject");
  123.                         } // has recycled?
  124.  
  125.                             */
  126.  
  127.                         if (args.undelable) {
  128.                             bits = bits | OTYPE_UNDELETABLE;
  129.                         }
  130.  
  131.                         errorcode = DoPkt(port, ACTION_SFS_SET_OBJECTBITS, 0, (ULONG) lock, namebcpl, bits, 0);
  132.                         if (errorcode==DOSFALSE) {
  133.                             Printf("Could not set object attributes!\n");
  134.                             PrintFault(IoErr(), "SFSobject");
  135.                         }
  136.  
  137.                         FreeDeviceProc(devproc);
  138.                     } // devproc
  139.                     UnLock(lock);
  140.                 } // lock
  141.                 else {
  142.                     PrintFault(IoErr(), "SFSobject");
  143.                 } // lock
  144.  
  145.             } // checking mutually exclusive options
  146.  
  147.         } // change something?
  148.  
  149.         FreeArgs(rdargs);
  150.     } // ReadArgs
  151. }
  152.  
  153.